<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta
        name="viewport"
        content="width=device-width, initial-scale=1.0"
    >
    <title>学生成绩管理系统</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f4f4f9;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
        }

        .container {
            background-color: white;
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
            width: 300px;
        }

        h1 {
            text-align: center;
            color: #333;
        }

        form {
            display: flex;
            flex-direction: column;
            gap: 10px;
        }

        label {
            font-weight: bold;
        }

        input[type="text"],
        input[type="number"] {
            padding: 10px;
            border: 1px solid #ccc;
            border-radius: 4px;
        }

        button {
            padding: 10px;
            background-color: #007bff;
            color: white;
            border: none;
            border-radius: 4px;
            cursor: pointer;
        }

        button:hover {
            background-color: #0056b3;
        }

        /* 取消超链接的下划线 */

        a {
            text-decoration: none;
        }
    </style>
</head>

<body>
    <div class="container">
        <h1>学生成绩管理系统</h1>
        <form id="add-student-form">
            <label for="id">ID：</label>
            <input
                type="text"
                id="id"
                name="id"
                required
            >
            <label for="name">姓名：</label>
            <input
                type="text"
                id="name"
                name="name"
                required
            >
            <label for="score">分数：</label>
            <input
                type="number"
                id="score"
                name="score"
                required
            >
            <button type="submit">添加学生</button>

        </form>
        <a href="{{ url_for('select_stu_score') }}">查询学生信息</a>
        <a href="{{ url_for('delete_student') }}">删除学生信息</a>


    </div>
    <div id="student-list"></div>
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script>
        $('#add-student-form').on('submit', function (event) {
            event.preventDefault();
            const id = $('#id').val();
            const name = $('#name').val();
            const score = $('#score').val();
            $.ajax({
                url: '/add_student',
                method: 'POST',
                data: { id: id, name: name, score: score }, // 使用表单数据格式
                success: function (response) {
                    console.log(response);
                    alert('学生添加成功！');
                    // 清空输入框
                    $('#id').val('');
                    $('#name').val('');
                    $('#score').val('');
                },
                error: function (error) {
                    console.log(error);
                    alert('添加学生失败，请重试！');
                }
            });
        });
    </script>
</body>

</html>